<?php
@include_once("classes/Mysql.php");
@include_once("services/classes/Mysql.php");
include_once("vo/mymyoux/io/AMFPHPClasses/Telegramme.php");        
@include_once("classes/Utils.php");
@include_once("services/classes/Utils.php");

class Admin
{
    function addLanguages($liste)
    {
        $u=new Telegramme();
        $req=new RequeteSQL();
        $req->req2void("TRUNCATE TABLE langue");
         foreach( $liste as $key => $value )
         {
             if(strlen($value)>0)
             {
                $req->req2void("INSERT INTO langue VALUES('".$key."','".$value."')");
             }
         }
         $u->setValue("succes");
         return $u;
    }
    function addKeys($liste)
    {
        $u=new Telegramme();
        $req=new RequeteSQL();
        $req->req2void("TRUNCATE TABLE langueclef");
        foreach($liste as $key => $value)
        {
            if(strlen($value>0))
            {
                  $req->req2void("INSERT INTO langueclef VALUES('".$key."','".$value[0]."','".$value[1]."')");
            }
        }
        $u->setValue("success");
        return $u;
    }
    function setTrads($liste)
    {
        $u=new Telegramme();
        $req=new RequeteSQL();
        $req->req2void("TRUNCATE TABLE language"); 
        foreach($liste as $key => $value)
        {
            if(strlen($value)>0)
            {
                $req->req2void("INSERT INTO language VALUES(0,'".$value[0]."','".$value[1]."','".$value[2]."')");
                $u->setValue($value[0]."','".$value[1]."','".$value[2]);
            }
        }
        return $u;
    }
    function getWords()
    {
        $u=new Telegramme();
        $req=new RequeteSQL();
        $tab=$req->req2tab("SELECT id_trad,id_clef,id_langue,clef,traduction,page FROM language NATURAL JOIN langueclef");
        $u->setValue($tab);
        return $u;
    }
    function getLanguages()
     {
         $retour=new Telegramme();
         $req=new RequeteSQL();
         $liste=$req->req2tab("SELECT * FROM `langue`");
         if(sizeof($liste)==0)
         {
            $this->create();
         }
         $retour->setValue($liste);
         return $retour;
     }
     function create()
     {
          $req=new RequeteSQL(); 
            $create_table=split(";","CREATE TABLE IF NOT EXISTS `language` (
                      `id_trad` int(6) unsigned NOT NULL AUTO_INCREMENT,
                      `id_langue` tinyint(2) unsigned NOT NULL,
                      `id_clef` int(5) unsigned NOT NULL,
                      `traduction` varchar(255) NOT NULL,
                      PRIMARY KEY (`id_trad`)
                    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;CREATE TABLE IF NOT EXISTS `langue` (
                      `id_langue` tinyint(2) unsigned NOT NULL,
                      `nom_langue` varchar(255) NOT NULL,
                      PRIMARY KEY (`id_langue`),
                      KEY `id_langue` (`id_langue`)
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE IF NOT EXISTS `langueclef` (
                      `id_clef` int(5) unsigned NOT NULL,
                      `clef` varchar(255) NOT NULL,
                      `page` int(4) unsigned NOT NULL,
                      PRIMARY KEY (`id_clef`),
                      UNIQUE KEY `id_clef` (`id_clef`,`clef`),
                      UNIQUE KEY `id_clef_2` (`id_clef`)
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;") ;
                  for($i=0;$i<sizeof($create_table);$i++)
                    {
                        if(strlen($create_table[$i])>0)
                        {
                            $req->req2void($create_table[$i]);
                        }
                    }        
     }
}

?>